- name: install supybot package
  yum: pkg={{ item }} state=present
  with_items:
  - supybot-gribble
  - supybot-fedora
  - supybot-koji
  - supybot-notify
  - supybot-pinglists
  - supybot-fedmsg
  - packagedb-cli
  tags: supybot

- name: creating zodbot log dir
  file: path={{ item }} state=directory owner=daemon
  with_items:
  - /var/lib/zodbot
  - /var/lib/zodbot/conf
  - /var/lib/zodbot/data
  - /var/lib/zodbot/logs
  - /srv/web
  - /srv/web/meetbot
  when: env != "staging"
  tags: supybot

- name: create teams directory
  file: path=/srv/web/meetbot/teams state=directory recurse=yes owner=apache group=apache mode=0755
  tags: supybot

- name: creating usrabot log dir
  file: path={{ item }} state=directory owner=daemon
  with_items:
  - /var/lib/ursabot
  - /var/lib/ursabot/conf
  - /var/lib/ursabot/data
  - /var/lib/ursabot/logs
  - /srv/web
  - /srv/web/meetbot
  when: env == "staging"
  tags: supybot

- name: setup meetings_by_team script
  copy: src=meetings_by_team.sh dest=/usr/local/bin/meetings_by_team.sh mode=755
  tags: supybot

- name: teams cron job
  cron: name=meetings-by-team hour="23" minute="0" user=apache job="/usr/local/bin/meetings_by_team.sh"
  tags: supybot

- name: setup meetbot.conf apache config
  copy: src=meetbot.conf dest=/etc/httpd/conf.d/meetbot.conf mode=644
  tags: supybot

- name: check the selinux context of the /srv/web/meetbot dir
  command: matchpathcon /srv/web/meetbot
  register: context
  always_run: yes
  changed_when: "1 != 1"
  tags:
  - config
  - selinux
  - meetbot
  - supybot

- name: /srv/web/meetbot file contexts
  command: semanage fcontext -a -t httpd_sys_content_t "/srv/web/meetbot(/.*)?"
  when: context.stdout.find('httpd_sys_content_t') == -1
  tags:
  - config
  - selinux
  - meetbot
  - supybot

- name: setup cron job to start zodbot/ursabot on boot
  cron: name=zodbot special_time=reboot job='cd /srv/web/meetbot; supybot -d /var/lib/zodbot/conf/zodbot.conf' user=daemon
  tags:
  - config
  - meetbot
  - supybot
  when: env != "staging"

- name: setup cron job to start zodbot/ursabot on boot
  cron: name=ursabot special_time=reboot job='cd /srv/web/meetbot; supybot -d /var/lib/ursabot/conf/ursabot.conf' user=daemon
  tags:
  - config
  - meetbot
  - supybot
  when: env == "staging"
